package main

import (
	"imgscrapy/server"
	"os"
	"path/filepath"
	"runtime"

	"github.com/joho/godotenv"
)

func main() {
	ROOT_PATH, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		panic(err)
	}
	if runtime.NumCPU() > 1 {
		runtime.GOMAXPROCS(runtime.NumCPU() - 1)
	}
	// 从配置文件读取配置

	os.Setenv("ROOT_PATH", ROOT_PATH)
	godotenv.Load(ROOT_PATH + "/.env")
	dirPath := ROOT_PATH + "/image"
	os.Setenv("OUT_PATH", dirPath)
	_, err = os.Stat(dirPath)
	if os.IsNotExist(err) {
		err := os.MkdirAll(dirPath, os.ModePerm)
		if err != nil {
			panic("权限不足")
		}
	}
	server.Server()
}
